#!/bin/bash
set -eux -o pipefail
IFS=$'\n\t'

for arg in $*; do
  # There can be some arguments prefixed in front of the executable, e.g.
  # when qemu-user is used. There can be arguments after the executable,
  # e.g. `cargo test` arguments like `TESTNAME`.
  if [[ $arg = */deps/* ]]; then
    executable=$arg
    break
  fi
done

export LLVM_PROFILE_FILE=$(dirname "$RING_BUILD_EXECUTABLE_LIST")/$(basename "$executable").profraw

if [ -n "$RING_BUILD_EXECUTABLE_LIST" ]; then
  echo "$executable" >> "$RING_BUILD_EXECUTABLE_LIST"
fi

$*
